/***************************************************
 * Author:		Xycaleth
 * Description:	Handles mod commands
 * Revision:	$Id$
 **************************************************/
#include "../game/g_local.h"
// ========================================

// ========================================
// S_DebugMessage - Debug message to see whats going on. Can be disabled easily.
// ========================================
void S_DebugMessage( int target, char *string )
{
	S_SendCommand( target, "chat", string );
}

// ========================================
// S_ClientCommand - Called for each command a user inputs.
// ========================================
void S_ClientCommand( int clientNum )
{
	gentity_t	*ent = g_entities + clientNum;
	char		cmd[MAX_TOKEN_CHARS];

	//
	// The client is not fully ingame yet, do not accept any commands.
	//
	if ( !ent->client ) 
	{
		return;
	}

	//
	// Get the command and start parsing trough our list!
	//
	trap_Argv( 0, cmd, sizeof( cmd ));

	//
	// Debug messages.
	//
	if ( Q_stricmp( cmd, "forceclass" ) == 0 )
	{
		char integer[MAX_TOKEN_CHARS];
		trap_Argv( 1, integer, sizeof( integer ));

		ent->client->pers.class_id = atoi( integer );

		S_DebugMessage( clientNum, va( "S_ClientCommand - Forced your class to %d! Max HP: %d, Max AP: %d", ent->client->pers.class_id, playerClasses[ent->client->pers.class_id].max_hp, playerClasses[ent->client->pers.class_id].max_ap));
		return;
	}

	//
	// Nothing was found for this command, call the Base functions.
	//
	NDA_ClientCommand( clientNum );
}

// ========================================
// S_SendCommand - Send a command to a client. Only for single-string commands.
// ========================================
void S_SendCommand( int target, char *cmd, char *string )
{
	trap_SendServerCommand( target, va("%s \"%s\"", cmd, string ) );
}

// ========================================
// S_DropPlayer - Drop a player from the server for the given reason. Safe drop.
// ========================================
void S_DropPlayer( gentity_t *ent, char *msg )
{
	if ( ent->client->sess.sessionTeam == TEAM_SPECTATOR )
	{
		ent->client->sess.spectatorState	= SPECTATOR_FREE;
		ent->client->sess.spectatorClient	= ent-g_entities;
	}

	trap_DropClient( ent-g_entities, msg );
}